/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.DAOs;

import com.ControlEscolar.Beans.Reticle;
import java.util.ArrayList;

/**
 *
 * @author Listico
 */
public class ReticleDAO extends AbstractDAO <Reticle>  {


    public int delete(String condition) throws DAOException {
      String sql = "DELETE FROM major WHERE ID_Mr=1";
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new DAOException();
        }
    return 0;
    }

    @Override
    public ArrayList query() throws DAOException {
        try {
            String sql = "SELECT * FROM reticle";
            return connection.executeQuery(sql, Reticle.class);

        } catch (Exception ex) {
            ex.printStackTrace();
            throw new DAOException();

        }}

    @Override
    public void add(Reticle reticle) throws DAOException {
           try {
            String sql = "INSERT INTO reticle(subjectKey,semester,ID_Curriculum)values(\""
                    + reticle.getSubjectKey() + "\","
                    + reticle.getSemester() + ","
                    + reticle.getID_Curriculum() + ")";

            connection.executeUpdate(sql);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new DAOException();
        }
    }

    @Override
    public int update(Reticle object) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

     public ArrayList<Reticle> queryBySubjectKey(String subjectKey) throws DAOException {
        try {
            String sql = "SELECT * FROM reticle where subjectKey = \""+subjectKey+"\"";
            return connection.executeQuery(sql, Reticle.class);

        } catch (Exception ex) {
            throw new DAOException();
        }
    }

    public  Reticle queryBySubjectKey(String subjectKey, int ID_Curriculum) throws DAOException{
         try {
           String sql = "SELECT * FROM reticle where subjectKey = \""+subjectKey+"\""+" and ID_Curriculum="+ID_Curriculum;
           ArrayList <Reticle> reticleQuery=connection.executeQuery(sql, Reticle.class);
           return getSpecificQuery(reticleQuery);

        } catch (Exception ex) {
            throw new DAOException();
        }

    }

    public ArrayList<Reticle> queryStudentReticles(int ID_Curriculum, int semester) throws DAOException {
        try {
            String sql = "SELECT * FROM reticle where ID_Curriculum= "+ID_Curriculum
                     +" and semester="+semester;
            return connection.executeQuery(sql, Reticle.class);

        } catch (Exception ex) {
            throw new DAOException();
        }
    }


    }







